package com.fourth.controller.api;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.fourth.feign.CommodityFeign;
import com.fourth.service.UbAliPayService;
import com.fourth.service.UbOrderService;
import com.fourth.util.GetUidUtil;
import com.fourth.vo.PayInfoVO;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Goods;
import com.ljx.entity.Order;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author Mr.ma
 * @since 2023/3/3 14:19
 **/
@RestController
@RequestMapping("/detail/order")
@Api("订单操作接口")
public class UbApiOrderController {

    @Resource
    private UbOrderService ubOrderService;

    @RequestMapping("hasBuyThisGoods/{id}")
    @ApiOperation("根据gooodsid查询是否购买过该商品")
    @ApiImplicitParam(name = "id", value = "商品编号", dataType = "String")
    public Result<List<Order>> hasBuyThisGoods(@PathVariable String id){
        List<Order> order = ubOrderService.hasBuyThisGoods(id);
        if (order.size() > 0){
            return new Result(2000,"已购买该商品",order);
        }
        return new Result(5000,"未购买该商品",null);
    }

    @RequestMapping("noCommentThisOrder/{id}")
    @ApiOperation("页面加载判断该用户是否有未评价过的订单")
    @ApiImplicitParam(name = "id", value = "商品编号", dataType = "String")
    public Result<List<String>> noCommentThisOrder(@PathVariable String id){
        List<Order> order = ubOrderService.noCommentOrder(id);
        if (order.size() > 0){
            return new Result(2000,"存在已购买但未评论的订单");
        }
        return new Result(5000,"不存在未评论的订单");
    }

    @RequestMapping("paystatus/{code}")
    @ApiOperation("根据code获取订单支付状态")
    @ApiImplicitParam(name = "code", value = "订单号", dataType = "String")
    public Result<List<Order>> payStatus(@PathVariable String code){
        List<Order> orders = ubOrderService.getOrderByCode(code);
        return new Result(2000,"查询订单信息成功",orders);
    }
}
